<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "course_teacher".
 *
 * @property int $ID ID
 * @property int $KKID 开课ID
 * @property int|null $JSID 教师ID
 * @property string $KCBH 课程排课编号
 *
 * @property CourseSchedule[] $courseSchedules
 * @property Teacher $jS
 * @property TermCourse $kK
 * @property Elective[] $electives
 */
class CourseTeacher extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'course_teacher';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['KKID', 'KCBH'], 'required'],
            [['KKID', 'JSID'], 'integer'],
            [['KCBH'], 'string', 'max' => 40],
            [['JSID'], 'exist', 'skipOnError' => true, 'targetClass' => Teacher::className(), 'targetAttribute' => ['JSID' => 'ID']],
            [['KKID'], 'exist', 'skipOnError' => true, 'targetClass' => TermCourse::className(), 'targetAttribute' => ['KKID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'KKID' => '开课ID',
            'JSID' => '教师ID',
            'KCBH' => '课程排课编号',
        ];
    }

    /**
     * Gets query for [[CourseSchedules]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getCourseSchedules()
    {
        return $this->hasMany(CourseSchedule::className(), ['JXKCID' => 'ID'])->inverseOf('jXKC');
    }

    /**
     * Gets query for [[JS]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getJS()
    {
        return $this->hasOne(Teacher::className(), ['ID' => 'JSID'])->inverseOf('courseTeachers');
    }

    /**
     * Gets query for [[KK]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getKK()
    {
        return $this->hasOne(TermCourse::className(), ['ID' => 'KKID'])->inverseOf('courseTeachers');
    }

    /**
     * Gets query for [[Electives]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getElectives()
    {
        return $this->hasMany(Elective::className(), ['JXKCID' => 'ID'])->inverseOf('jXKC');
    }
}
